<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>${news.ntitle} - AnonyEast's 新闻门户</title>
    <link href="css/read.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="js/news.js"></script>
    <script type="text/javascript">
        function check() {
            var cauthor = document.getElementById("cauthor");
            var content = document.getElementById("ccontent");
            if (cauthor.value == "") {
                alert("用户名不能为空！！");
                return false;
            } else if (content.value == "") {
                alert("评论内容不能为空！！");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<div id="header">
    <div id="top_login">
        <form action="userServlet/news" method="post">
            <input type="hidden" name="method" value="login"/>
            <label> 登录名 </label>
            <input type="text" name="uname" value="" id="uname" class="login_input"/>
            <label> 密&#160;&#160;码 </label>
            <input type="password" name="upwd" value="" id="upwd" class="login_input"/>
            <input type="submit" class="login_sub" value="登录"/>
            <label id="error" style="color: red">${loginError_msg}</label>
            <a href="indexServlet" class="login_link">返回首页</a>
            <img src="images/friend_logo.gif" alt="Google" id="friend_logo"/>
        </form>
    </div>
    <div id="nav">
        <div id="logo"><a href="indexServlet"><img src="images/logo.jpg" alt="新闻中国" /></a></div>
        <div id="a_b01"><img src="images/a_b01.gif" alt=""/></div>
        <!--mainnav end-->
    </div>
</div>
<div id="container">
    <div style="float: left;width: 157px;">
        <%@ include file="../index-elements/index_sidebar.jsp" %>
    </div>
    <div class="main">
        <div class="class_type"><img src="images/class_type.gif" alt="新闻中心"/></div>
        <div class="content">
            <ul class="classlist">
                <table width="80%" align="center">
                    <tr width="100%">
                        <td colspan="2" align="center"><h2>${news.ntitle}</h2></td>
                    </tr>
                    <tr>
                        <td colspan="2"><br></td>
                    </tr>
                    <tr>
                        <td align="left" style="font-size: 16px">作者：${news.nauthor}</td>
                        <td align="left" style="font-size: 16px">发布时间：${news.ncreateDate}</td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><br>${news.ncontent}</td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <hr/>
                        </td>
                    </tr>
                </table>
            </ul>
            <ul class="classlist">
                <table width="80%" align="center">
                    <c:choose>
                        <c:when test="${empty comments}">
                            <tr>
                                <td colspan="6"> 暂无评论！</td>
                            </tr>
                            <tr>
                                <td colspan="6">
                                    <br>
                                    <hr/>
                                </td>
                            </tr>
                        </c:when>
                        <c:otherwise>
                            <c:forEach items="${comments}" var="comment">
                                <tr>
                                    <td> 留言人：</td>
                                    <td>${comment.cauthor}</td>
                                    <td> IP：</td>
                                    <td>${comment.cip}</td>
                                    <td> 留言时间：</td>
                                    <td>${comment.cdate}</td>
                                </tr>
                                <tr>
                                    <td colspan="6">${comment.ccontent}</td>
                                </tr>
                                <tr>
                                    <td colspan="6">
                                        <br>
                                        <hr/>
                                    </td>
                                </tr>
                            </c:forEach>
                        </c:otherwise>
                    </c:choose>
                </table>
            </ul>
            <ul class="classlist">
                <form action="commentsServlet" method="post">
                    <input type="hidden" id="nid" name="cnid" value="${news.nid}"/>
                    <input type="hidden" name="method" value="addComment"/>
                    <table width="80%" align="center">
                        <tr>
                            <td> 评 论</td>
                        </tr>
                        <tr>
                            <td> 用户名：</td>
                            <td>
                                <c:choose>
                                    <c:when test="${not empty sessionScope.admin}">
                                        <input id="cauthor" name="cauthor" value="${sessionScope.admin}"
                                               readonly="readonly" style="border:0px;"/>
                                    </c:when>
                                    <c:otherwise>
                                        <input id="cauthor" name="cauthor" value="这家伙很懒什么也没留下"/>
                                    </c:otherwise>
                                </c:choose>
                                IP：
                                <input name="cip" id="cip" value="${pageContext.request.remoteAddr}" readonly="readonly"
                                       style="border:0px;"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2"><textarea name="ccontent" id="ccontent" cols="70" rows="10"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <%--                <input id="commentSubmit" name="submit" value="发  表" type="button"/>--%>
                                <input name="submit" value="发  表" type="submit"/>
                            </td>
                        </tr>
                    </table>
                </form>
            </ul>
        </div>
    </div>
</div>
<%--
    request.removeAttribute("news_view");
    request.removeAttribute("comments_view");
--%>
<%@ include file="../index-elements/index_bottom.html" %>
</body>
</html>
